import {createRouter, createWebHistory} from 'vue-router'
import {useStore} from "@/stores/store.js";
import Framework from "@/components/template/Framework.vue";

const routes = [
  {
    path: '/login',
    name: 'login',
    component: () => import('@/views/login/Login.vue')
  },
  {
    path: '//',
    redirect: '/home'
  },
  {
    component: Framework,
    children: [
      {
        path: '/home',
        name: 'home',
        meta: {
          // description: '这是首页，欢迎来到我们的应用程序！'
        },
        component: () => import('@/views/home/Home.vue')
      },
      {
        path: '/approval/musician',
        name: 'MusicianApproval',
        meta: {
          description: '这是音乐人申请审批页面，请公正处理每一个申请！'
        },
        component: () => import('@/views/approval/MusicianApproval.vue')
      },
      {
        path: '/approval/album',
        name: 'AlbumApproval',
        meta: {
          description: '这是专辑申请审批页面，请公正守规，完成专辑审批！'
        },
        component: () => import('@/views/approval/AlbumApproval.vue'),
      },
      {
        path: '/management/musician',
        name: 'MusicianManagement',
        meta: {
          description: '这是音乐人管理页面，请合理对音乐人做出各项处理！'
        },
        component: () => import('@/views/management/MusicianManagement.vue')
      },
      {
        path: '/post/management',
        name: 'PostManagement',
        meta: {
          description: '这是帖子管理页面，请合理对各个帖子完成各种操作！'
        },
        component: () => import('@/views/post/PostManagement.vue')
      },
      {
        path: '/post/hot',
        name: 'PostHot',
        meta: {
          description: '这是帖子热度管理页面，请合理对各个帖子完成各种操作！'
        },
        component: () => import('@/views/post/PostHot.vue')
      },
      {
        path: '/management/comment',
        name: 'CommentManagement',
        meta: {
          description: '这是评论管理页面，请对评论功能做好合理的风险管控和舆情控制！'
        },
        component: () => import('@/views/management/CommentManagement.vue')
      },
      {
        path: '/data/management',
        name: 'DataManagement',
        meta: {
          description: '这是数据管理页面，欢迎来到我们的应用程序！'
        },
        component: () => import('@/views/data/DataManagement.vue')
      },
      {
        path: '/data/view',
        name: 'DataView',
        meta: {
          description: '这是首页，欢迎来到我们的应用程序！'
        },
        component: () => import('@/views/data/DataView.vue')
      }
    ]
  },
  {
    path: '/:catchAll(.*)',
    name: 'NotFound',
    component: () => import('@/views/error/NotFound.vue')
  }


];

const router = createRouter({
  history: createWebHistory(),
  routes
});

// 设置路由守卫，在进页面之前，判断有token，才进入页面，否则返回登录��面
router.beforeEach((to, from, next) => {
  const token = useStore().admin.token
  if (!token && to.path!== '/login') {
    next('/login');
  } else {
    next();
  }
});

export default router
